<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<!-- import CSS -->
		<script src="../../js/commonCss.js"></script>
		<title>保险公司管理</title>
	</head>
	<body>
		<div id="app" v-cloak>
			<div class="pd10 border-bottom ft-14 h40">
				保险公司管理
				<el-button class="f-r" type="primary" icon="el-icon-plus" @click="addCont">添加保险公司</el-button>
			</div>
			<div class="pd10">		
				<el-form :inline="true" :model="formInline" class="demo-form-inline">					
					<el-form-item>
						<el-input v-model="formInline.icTitle" type="text" placeholder="请输入名称"></el-input>
					</el-form-item>
					<el-form-item>
						<el-button type="primary" @click="search">查询</el-button>
					</el-form-item>
				</el-form>
				<el-table :data="tableData" stripe border style="width: 100%">
					<el-table-column prop="icTitle" label="保险公司名称"></el-table-column>
					<el-table-column prop="icRecommend" label="是否热门">
						<template slot-scope="scope">
							{{({"0":"否","1":"是"}[scope.row.icRecommend])}}
						</template>
					</el-table-column>
					<el-table-column label="操作">
						<template slot-scope="scope">
							<el-button @click="handleEdit(scope.row)" type="text" size="medium">编辑</el-button>
							<el-button @click="handleDelete(scope.row)" type="text" size="medium" class="color-F56C6C">删除</el-button>
						</template>
					</el-table-column>
				</el-table>				
				<!-- 分页 -->
				<!-- <div class="bottomstate">
					<el-pagination class="f-r mt5" background @current-change="handleCurrentChange" :current-page="page" :page-size="limit" layout="total,prev, pager, next,jumper"
					 :total="total" ></el-pagination>
				</div> -->
			</div>
			<!-- 修改 -->
			<el-dialog :title="title" :visible.sync="dialogFormVisible">
				<el-form :model="form" label-width="120px">
					<el-form-item label="保险公司名称" >
						<el-input v-model="form.icTitle" autocomplete="off" style="width:300px;"></el-input>
					</el-form-item>
				</el-form>
				<el-form :model="form" label-width="120px">
					<el-form-item label="是否热门" >
						<el-select v-model="form.icRecommend" placeholder="请选择">
							<el-option :label="item.label" :value="item.value" v-for="item in hotArr" :key="item.label"></el-option>
						</el-select>
					</el-form-item>
				</el-form>
				<div class="dialog-footer text-r">
					<el-button @click="dialogFormVisible = false">取 消</el-button>
					<el-button type="primary" @click="onSubmit">确 定</el-button>
				</div>
			</el-dialog>
		</div>
	</body>
	<script src="/jeefast/elementui-lib/lib/vue.js"></script>
	<script src="/jeefast/elementui-lib/lib/index.js"></script>
	<script src="/jeefast/js/jquery-1.9.1.min.js"></script>
	<script src="/jeefast/js/axios.js"></script>
	<script src="/jeefast/js/data.js"></script>
	<script>
		var app = new Vue({
			el: "#app",
			mixins: [mix],
			data: function() {
				return {
					formInline:{
						icTitle:""
					},
					tableData: [],
					total:0,
					hotArr:[{
						value:0,
						label:"否"
					},{
						value:1,
						label:"是"
					}],
					// 修改
					title:"",
					dialogFormVisible: false,
					form: {
						icId:"",
						icTitle: "",
						icRecommend:""
					},
				}
			},
			methods: {
				search:function(){
					this.getTable();
					console.log(this.formInline)
				},
				addCont:function(){
					this.title="添加保险公司"
					this.form.icId=""
					this.form.icTitle=""
					this.form.icRecommend=""
					this.dialogFormVisible=true
				},
				handleEdit:function(row){
					console.log(row)
					this.title = "编辑保险公司"
					this.form.icId=row.icId
					this.form.icTitle=row.icTitle
					this.form.icRecommend=row.icRecommend
					this.dialogFormVisible = true
				},
				// 删除
				handleDelete:function(row){
					let that = this
					that.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
						confirmButtonText: '确定',
						cancelButtonText: '取消',
						type: 'warning'
					}).then(() => {
						that.$message({
							type: 'success',
							message: '删除成功!'
						});
					this.getTable();
					}).catch(() => {
						that.$message({
							type: 'info',
							message: '已取消删除'
						});          
					});
				},
				// 确定
				IsNull: function() {
					let flag = false;
					if (this.form.icTitle == "") {
						this.$message.error('名称不能为空');
						return flag = true;
					}
					if (this.form.icRecommend === "") {
						this.$message.error('是否热门');
						return flag = true;
					}
				},
				onSubmit:function(){
					let that = this;
					if (that.IsNull()) {
						return;
					}
					addOrSaveCompany(this.form).then(res=>{
						if(res.data.code==0){							
							this.dialogFormVisible = false
							this.getTable()
						}
					})					
				},
				getTable:function(){
					companyList({						
						icTitle:this.formInline.icTitle,
						page: this.page, //起始页面
						limit: this.limit, //每页显示个数
					}).then(res=>{
						if(res.data.code==0){
							this.tableData=res.data.data
						}
					})
				}
			},
			created() {
				this.getTable()
			},
		});
	</script>
</html>
